package mymyoux.ai
{
	import flash.net.registerClassAlias;
	
	import mymyoux.signals.Signal;
	import mymyoux.utils.Arrays;

	/**
	 * Nerve. It's linked to input and output neurons
	 */
	public class Nerve extends Neuron
	{
		/**
		 * @private
		 */
		private static const ALIAS:* = registerClassAlias( "mymyoux.ai.Nerve", Nerve );
		/**
		 * Create a nerve object
		 */
		public function Nerve()
		{
			super();
			_signalResult = new Signal();
		}
		/**
		 * dispatches an input value to its neuron
		 */
		public function get value():Number
		{
			return _value;
		}
		public function set value(val:Number):void
		{
			_value = val;
			signalResult.dispatch(_value);
		}
		/**
		 *	@inheritDoc
		 */
		public override function toString():String
		{
			return "[Nerve"+super.toString().substring(7);
		}
		/**
		 *	@inheritDoc
		 */
		public override function toLongString(id:uint = 0):String
		{
			try
			{
				return "[Nerve"+super.toLongString().substring(7);	
			}catch(error:Error)
			{
				return "[Nerve Resursive Error]";
			}
			return "[Nerve Resursive Error]";
		}
		/**
		 *	@inheritDoc
		 */
		protected override function execute():void
		{
			var inputs:Array = Arrays.vectorToArray(_inputs);
			inputs.shift();
			signalResult.dispatch.apply(null, inputs);
			//super.execute();
		}
	}
}